/**
 * 字符串转换为浮点数,增加指数处理部分
 */

#include <stdio.h>
#include <ctype.h>

double atof(char s[]);

int main() {
    printf("%g\n", atof("-32.992e-30"));

    return 0;
}

double atof(char s[]) {
    double val, power;
    int i, sign;
    i = 0;
    while (isspace(s[i++])) ;
    sign = (s[i] == '-')? -1: 1;
    if (s[i] == '-' || s[i] == '+') i++;
    for (val = 0; isdigit(s[i]); i++) {
        val = val * 10 + s[i] - '0';
    }
    if (s[i] == '.') i++;
    for (power = 1.0; isdigit(s[i]); i++) {
        val = val * 10 + s[i] - '0';
        power *= 10;
    }
    if (tolower(s[i++]) == 'e') {
        int exp, expsign;
        expsign = (s[i] == '-')? -1: 1;
        if (s[i] == '-' || s[i] == '+') i++;
        for (exp = 0; isdigit(s[i]); i++) {
            exp = 10 * exp + s[i] - '0';
        }
        for (i = 0; i < exp; i++) {
            val *= (expsign > 0)? 10: 0.1;
        }
    }
    return sign * val / power;
}
